home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / Demos / Geospace 3D Trial / Geo3d12010Setup.exe / Dark Basic Pro / htMap.dba next >
Encoding:
Text File  |  2003-12-16  |  2.7 KB  |  135 lines

  1. sync on
  2. sync rate 60
  3.  
  4. hide mouse
  5.  
  6. autocam off
  7. randomize timer()
  8.  
  9. color light 0, rgb(255, 255, 255)
  10.  
  11. `overall position of last matrix
  12. global posX# = 0
  13. global posZ# = 0
  14.  
  15. `-----------------------------------------------------------
  16. `ALTER THE FOLLOWING VARIABLE TO LOAD YOUR EXPORTED FILE
  17. `-----------------------------------------------------------
  18. filename$ = "matrix.gdb"
  19.  
  20. `open the main file to find the files to load
  21. open to read 2 , filename$
  22.  
  23. `number of db units wide the overall heightmap is
  24. global pixelsX# = 0
  25. global pixelsZ# = 0
  26.  
  27. `read the total size in db units of x and z
  28. read float 2 , pixelsZ#
  29. read float 2 , pixelsX#
  30.  
  31. `number in the X by Z grid of matrices
  32. ZMatrices = 0
  33. XMatrices = 0
  34. read long 2 , ZMatrices
  35. read long 2 , XMatrices
  36.  
  37. `store a count so we can assign a unique matrix number
  38. count = 1
  39.  
  40. `load all the matrices in the exported grid
  41. for z = 0 to ZMatrices-1
  42.  
  43.    lastZ# = 0
  44.  
  45.    for x = 0 to XMatrices-1
  46.        read string 2, dbmName$
  47.        read string 2, bmpName$
  48.  
  49.        lastZ# = LoadMatrix( count, dbmName$, bmpName$ )
  50.        count = count + 1
  51.     next x
  52.  
  53.     posX# = 0
  54.     posZ# = posZ# - lastZ#
  55.  
  56. next z
  57.  
  58. close file 2
  59.  
  60. `setup camera
  61. Make Camera 1
  62. SET CAMERA RANGE 1, 1, 8000
  63. position camera 1, 0, 400, 0
  64. point camera 1, 100, 0, -100
  65.  
  66. `main loop
  67. repeat
  68.  
  69.    control camera using arrowkeys 1, 100, 10
  70.  
  71.    `show FPS and message
  72.    text 10, 10, "FPS : " + str$(screen fps())
  73.    text 10, 20, "ESC to exit"
  74.    text 10, 30, "cp : " + str$( cp/1.0 )
  75.  
  76.    sync
  77. until escapekey()
  78.  
  79. delete camera 1
  80.  
  81. show mouse
  82.  
  83. function LoadMatrix( matrixNumber, fileName$, textureName$ )
  84.  
  85.    `read the matrix file
  86.    open to read 1 , fileName$
  87.  
  88.    `get the x and z tile values
  89.    dimx = 0
  90.    dimz = 0
  91.    read long 1 , dimx
  92.    read long 1 , dimz
  93.  
  94.    `get the db units x and z values
  95.    sizeX# = 0
  96.    sizeZ# = 0
  97.    read float 1 , sizeX#
  98.    read float 1 , sizeZ#
  99.  
  100.    `create matrix
  101.    make matrix matrixNumber, sizeX#, sizeZ#, dimx , dimz
  102.  
  103.    position matrix matrixNumber, posX# , 0 , posZ#
  104.  
  105. !   posX# = posX# + sizeX#
  106.  
  107.    `read in the height data
  108.    for z = dimz to 0 step -1
  109.       for x = 0 to dimx
  110.             read float 1 , ht#
  111.             set matrix height matrixNumber ,x , z, ht#
  112.       next x
  113.    next z
  114.  
  115.    close file 1
  116.  
  117.    `sort out the texture
  118.    load image textureName$,matrixNumber
  119.    prepare matrix texture matrixNumber,matrixNumber, dimx, dimz
  120.  
  121.    in=1
  122.  
  123.    for z=dimz-1 to 0 step -1
  124.       for x=0 to dimx-1
  125.          set matrix tile matrixNumber,x,z,in
  126.          in = in + 1
  127.       next x
  128.    next z
  129.  
  130.    set matrix texture matrixNumber, 2, 0
  131.  
  132.    update matrix matrixNumber
  133.  
  134. endfunction sizeZ#
  135.